package com.boge.modules.house.controller;

import java.util.Arrays;
import java.util.Map;

import com.boge.modules.sys.entity.SysUserEntity;
import com.boge.modules.sys.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.boge.modules.house.entity.TReservationEntity;
import com.boge.modules.house.service.TReservationService;
import com.boge.common.utils.PageUtils;
import com.boge.common.utils.R;



/**
 * 
 *
 * @author boge
 * @email dengpbs@163.com
 * @date 2024-12-04 22:12:55
 */
@RestController
@RequestMapping("house/treservation")
public class TReservationController {
    @Autowired
    private TReservationService tReservationService;

    @Autowired
    private SysUserService userService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    //@RequiresPermissions("house:treservation:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tReservationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    //@RequiresPermissions("house:treservation:info")
    public R info(@PathVariable("id") Integer id){
		TReservationEntity tReservation = tReservationService.getById(id);

        return R.ok().put("tReservation", tReservation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    //@RequiresPermissions("house:treservation:save")
    public R save(@RequestBody TReservationEntity tReservation){
        // 传递的是用名称
        SysUserEntity sysUserEntity = userService.queryByUserName(tReservation.getUserName());
        tReservation.setUserId(sysUserEntity.getUserId().intValue());
        tReservation.setName(sysUserEntity.getUsername());
        tReservation.setPhone(sysUserEntity.getMobile());
        tReservationService.save(tReservation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    //@RequiresPermissions("house:treservation:update")
    public R update(@RequestBody TReservationEntity tReservation){
		tReservationService.updateById(tReservation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    //@RequiresPermissions("house:treservation:delete")
    public R delete(@RequestBody Integer[] ids){
		tReservationService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
